<!DOCTYPE html>
<html>
<head>
    <title>多线程分片文件上传</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>多线程分片文件上传</h1>
<input type="file" id="fileInput" />
<button onclick="uploadFile()">上传</button>
<div id="progressBar"></div>

<h1>&lt;script&gt whilt(){alert(1)} &lt;/script&gt</h1>

<script>
    function uploadFile() {
        var fileInput = document.getElementById('fileInput');
        var file = fileInput.files[0];
        var chunkSize = 20480 * 20480; // 分片大小为20G

        var totalChunks = Math.ceil(file.size / chunkSize);
        var currentChunk = 0;

        var progressBar = document.getElementById('progressBar');
        progressBar.innerHTML = '上传中...';

        var uploadChunk = function(start, end) {
            var formData = new FormData();
            formData.append('file', file.slice(start, end));

            $.ajax({
                url: '/upload',
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function() {
                    currentChunk++;
                    var progress = Math.round((currentChunk / totalChunks) * 100);
                    progressBar.innerHTML = '上传进度: ' + progress + '%';

                    if (currentChunk < totalChunks) {
                        var nextStart = currentChunk * chunkSize;
                        var nextEnd = nextStart + chunkSize;
                        uploadChunk(nextStart, nextEnd);
                    } else {
                        progressBar.innerHTML = '上传完成!';
                    }
                },
                error: function() {
                    progressBar.innerHTML = '上传失败!';
                }
            });
        };

        uploadChunk(0, chunkSize);
    }


</script>
</body>
</html>
